// void, Obj This

Building this;
Unit unit;
point ptDest, pt;
int i, pop_group, lRadius;
int  xfix, yfix;
str strMaleVillager, strFemaleVillager;

pop_group = GetConst("PopGroup");
lRadius = GetConst("VillageTrainPeasantRadius");
this = This.AsBuilding();
.Progress();

/// Gaul -> "GVillager" and "GWVillager", etc
strMaleVillager = .raceStrPref;
if (.race == ImperialRome)
	strMaleVillager = GetRaceStrPref(RepublicanRome);
strFemaleVillager = strMaleVillager + "W" + "Villager";
strMaleVillager = strMaleVillager + "Villager";

xfix = 1;
yfix = 1;

for (i = 0; i < pop_group; i += 1)
{
	ptDest.Set(1,1);
	ptDest.SetLen(rand(lRadius - .settlement.GetCentralBuilding().radius) + .settlement.GetCentralBuilding().radius );
	ptDest.Rot(rand(360));
	ptDest = ptDest + .settlement.GetCentralBuilding().pos;

	pt = .GetExitPoint(ptDest, false);
	
	if( i == 0 )
		pt.Set( pt.x + 10, pt.y + 10 );
	else if( i == 1 )
		pt.Set( pt.x - 10, pt.y - 10 );
	else if( i == 2 )
		pt.Set( pt.x - 10, pt.y + 10 );
	else if( i == 3 )
		pt.Set( pt.x + 10, pt.y - 10 );
	else
		pt.Set( pt.x + 10, pt.y );
	
	Sleep(rand(100)+100);
	unit = Place(strMaleVillager, pt, .player).AsUnit();

	if(unit.IsValid){
		//pr(EnvReadString(.settlement, "tribute_people"));
		if(EnvReadString(.settlement, "tribute_people") == "on"){
		
			.settlement.ForceAddUnit(unit); // wysylaniem zajmie sie village_idle.vs
			Sleep( 150 );
			
		} else {
			unit.SetCommand("move", ptDest);
			Sleep( 150 );
		}
	}
}
